package chpt06;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollectionsTest {

	public static void main(String[] args) {
		List<String> list = new ArrayList<>();
        list.add("cc");
        list.add("bb");
        list.add("aa");
        // addAll：添加多个元素
        Collections.addAll(list, "ee","dd","ff");
        System.out.println("list: " + list);
        // binarySearch 二分查找，必须在有序的集合中查找,返回-4
        System.out.println("cc所在位置："
        		+ Collections.binarySearch(list,"cc"));
        // sort:升序排序
        Collections.sort(list);
        System.out.println("排序后的list:" + list);
        // binarySearch 二分查找，必须在有序的集合中查找,返回2
        System.out.println("排序后cc所在位置："
        		+ Collections.binarySearch(list,"cc"));
        // reverse:逆序
        Collections.reverse(list);
        System.out.println("逆序后的list：" + list);
        // copy：将集合other中的元素全部复制到list中,并且覆盖相应索引的元素
        List<String> other = new ArrayList<>();
        Collections.addAll(other, "11","22");
        Collections.copy(list, other);
        System.out.println("copy后的list：" + list);
        // fill:用对象o替换集合list中的所有元素
        Collections.fill(list, "hello");
        System.out.println("fill后的list："+list);
	}
}
